<?php
	require('includes/config.php');
	require('core/database.php');
	require('core/functions.php');
	
	include 'modules/cart.php';
	
	$shoppingcart = new cartWrapper();
	require_once "core/cartClass.php";

	include ("pquery.php");
	$pquery= new PQuery();

	$action = $_GET["action"];

	switch ($action) {
		case "empty":
			$cart_object->emptyCart();
  			break;
  			
  		case "add":
  			$item_name = $shoppingcart->getItemVars(treatGet($_GET['pid']), 'item_name');
  			$item_desc = $shoppingcart->getItemVars(treatGet($_GET['pid']), 'item_desc');
  			$item_price = $shoppingcart->getItemVars(treatGet($_GET['pid']), 'item_price');
			$cart_object->addItem(new faucartelement($item_name,$item_desc,$item_price));
	  		break;
   
		case "add-own":
			$vid = $_GET['vid'];
  			
  			$query = $database->query("SELECT * FROM main WHERE  id = '$vid'");

  			while ($list = mysql_fetch_array($query)) {
    			$vid = $list['id'];
    			$first_name = $list['first_name'];
    			$middle = $list['middle'];
    			$last_name = $list['last_name'];
  			}
    
  			$item_name = $shoppingcart->getItemVars(treatGet($_GET['pid']), 'item_name');
  			$item_desc = $shoppingcart->getItemVars(treatGet($_GET['pid']), 'item_desc');
  			$item_price = $shoppingcart->getItemVars(treatGet($_GET['pid']), 'item_price');

  			// todo: figure out why faucartelement2...
  			$cart_object->addItem(new faucartelement2(''.$item_name.' for '.$first_name .' '.$middle.' '.$last_name.'' ,$item_desc,$item_price, $_GET['vid']));
  			break;
  		
  		// todo: donations??? cruft code?
  		case "add-donation":
  			$item_name = $shoppingcart->getItemVars(treatGet($_GET['pid']), 'item_name');
  			$item_desc = $shoppingcart->getItemVars(treatGet($_GET['pid']), 'item_desc');
  			$cart_object->addItem(new faucartelement(''.$item_name.' Donation',$item_desc,$_GET['price']));
  			break;
   
		case "add-custom":
  			$pd_price = $_GET['price'];
  			$pd_desc = $_GET['description'];
  			$pd_name = $_GET['name'];
			$cart_object->addItem(new faucartelement($pd_name,$pd_desc,$pd_price));
  			break;

		case "del":
   		$cart_object->delItemByObjectID($_GET["id"]);
   		break;
	}
	
	$cart_object->total();
	$total = $cart_object->_total;
	$cart_items = $cart_object->getItems();
?>
